package com.chuanwei.controller;

import com.chuanwei.pojo.Emp;
import com.chuanwei.pojo.EmpQueryParam;
import com.chuanwei.pojo.PageResult;
import com.chuanwei.pojo.Result;
import com.chuanwei.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 员工管理的Controller
 */
@RequestMapping ("/emps")
@RestController
@Slf4j
public class EmpController {

    @Autowired
    private EmpService empService;

    @GetMapping
    public Result page( EmpQueryParam empQueryParam){
        log.info("查询员工信息，{}",empQueryParam );
        PageResult<Emp>  pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 新增员工
     * @param emp
     * @return
     */
    @PostMapping
    public Result save(@RequestBody Emp emp){
        log.info("新增员工，{}",emp);
        empService.save(emp);
        return Result.success();
    }

    /**
     * 根据员工的id删除员工信息
     * @param ids
     * @return
     */
    @DeleteMapping
    public  Result delete(@RequestParam List<Integer> ids ){
        log.info("删除员工：{}",ids);
        empService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 根据员工id查询员工信息-- 查询回显
     * @return
     */
    @GetMapping("/{id}")
    public Result  getInfo(@PathVariable Integer id){
        log.info("根据id查询员工信息");
        Emp emp  =  empService.getInfo(id);
        return Result.success(emp);
    }

    /**
     * 修改员工
     */
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工：{}",emp);
        empService.update(emp);
        return Result.success();
    }







}
